package com.example.frame;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

/**
 * 作者: Andy
 * 时间: 2017-06-14
 * 描述:
 */

public class ImageFrameAdapter extends AbsFrameAdapter<ImageResp> {

    private Context mContext;

    public ImageFrameAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageResp bean = getItem(position);
        if (position == 4) {
            //最后一个特殊处理
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_last_image_layer, null);
            ImageView imageView = (ImageView) convertView.findViewById(R.id.iv_image);
            Glide.with(mContext).load(bean.getUrl()).into(imageView);
            final int leftCount = getCount() - position - 1;
            if (leftCount > 0) {
                TextView tvMessage = (TextView) convertView.findViewById(R.id.tv_message);
                tvMessage.setText(String.format("+%d", leftCount));
            }
        } else {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_image_layer, null);
            ImageView imageView = (ImageView) convertView.findViewById(R.id.iv_image);
            Glide.with(mContext).load(bean.getUrl()).into(imageView);
        }
        return convertView;
    }

}
